package com.mcptt.notify.presence;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.jdom.Element;
import org.jdom.JDOMException;

import com.cloudptt.api.product.log.Log;

public class Status
{
    public static final String Name = "status";

    private List<Affiliation> affiliationList = null;
    
    

    public void parse(Element elem) throws JDOMException
    {
	if(elem == null)
	{
	    return;
	}
	affiliationList = new Vector<Affiliation>();

	List<Element> list = elem.getChildren();//锟斤拷酶锟斤拷诘锟斤拷锟接节碉拷  
	for(Element subElem:list) 
	{
	    String name = subElem.getName();
	    Log.debug(this.getClass(), "name = " + name);
	    if(name == null
		    || name.length() <= 0)
	    {
		return;
	    }
	    if(name.equals(Affiliation.Name))
	    {
		Affiliation doc = new Affiliation();
		doc.parse(subElem);
		affiliationList.add(doc);
	    }
	}  
    }

    public List<Affiliation> getAffiliationList()
    {
        return affiliationList;
    }
    
    public String toString()
    {
	StringBuffer strBuf = new StringBuffer("\r\n");
	strBuf.append("<").append(Name).append(">");
	for(Iterator<Affiliation> itor = affiliationList.iterator();itor.hasNext();)
	{
	    strBuf.append(itor.next());
	}
	strBuf.append("</").append(Name).append(">");

	return strBuf.toString();
    }
}
